angular.module('payPcApp')
    .filter("flatinfo", function() {
        return function(flat, sep) {
            var flat_array = flat.split("-");
            var fin = '';
            if (sep == 'live') {
                fin = flat_array[0];
            } else if (sep == 'flat') {
                fin = flat_array[1];
            } else {
                fin = flat_array[2];
            }
            return fin;
        };
    })
    .filter("time_compose", function() {
        return function(detail) {
            var year = detail.year + 1900;
            var month = detail.month + 1;
            var day = detail.date;
            return year + '/' + month + '/' + day;
        };
    })
    .filter('book_state', function() {
        return function(detail) {
            if (detail == 0) {
                return '可借';
            }
            if (detail == 1) {
                return '未上架';
            }
            if (detail == 2) {
                return '借出';
            }
            return '未上架';

        }
    })
    .filter('dep_name', function() {
        return function(detail, dep_list) {
            var dep_name = '';
            var la = _.find(dep_list, function(dep) {
                if (dep.higher.id == detail) {
                    dep_name = dep.higher.name;
                    return;
                }
                var find = _.find(dep.lower, function(dep_lower) {
                    if (dep_lower.id == detail) {
                        dep_name = dep_lower.name;
                        return;
                    }
                });
                if (find != undefined) {
                    return find;
                };
            });
            return dep_name;
        }
    })
    .filter("time_replace", function() {
        return function(detail) {
            var time = detail.UpdatedOn ? detail.UpdatedOn : detail.CreatedOn;
            var str = time.replace(/-/g, '/').replace("T", " ");
            var date = new Date(str);
            return date.format('MM-dd h:m');
        };
    })
    .filter('account_percent', function() {
        return function(detail) {
            var pre = Math.floor(detail / 5) * 5 / 100 * 360 + 90;
            console.log(pre);
            return pre + 'deg';
        }
    })
    .filter("level_name", function() {
        return function(detail) {

            var detail = parseInt(detail);
            console.log(detail);
            var name = '';
            switch (detail) {
                case 4:
                    name = '驾驶员'
                    break;
                case 6:
                    name = '管理员'
                    break;
                case 9:
                    name = '最高管理员'
                    break;
                default:
                    name = '普通员工';
            }
            return name;

        }
    })